package com.jie.common.http.util;

import com.jie.common.http.constant.HttpHeaderLineNameConstant;
import com.jie.common.http.entity.HttpEntityBody;
import com.jie.common.http.entity.HttpHeaderLine;

/**
 * http工具类
 * @author XieZhiJie
 * @date 2022/04/21 21:15
 */
public class HttpUtil {

    /**
     * 组装首部行和实体
     * @param httpHeaderLine 首部行
     * @param httpEntityBody 实体
     * @param bytes          字节数组
     * @param bytesIndex     字节数组开始索引
     */
    public static void packageHeaderAndEntity(HttpHeaderLine httpHeaderLine, HttpEntityBody httpEntityBody, byte[] bytes, int bytesIndex) {
        bytesIndex = httpHeaderLine.addParamToMap(bytes, bytesIndex);
        bytesIndex += 2;
        byte[] entityDataBytes = new byte[bytes.length - bytesIndex];
        System.arraycopy(bytes, bytesIndex, entityDataBytes, 0, entityDataBytes.length);

        httpEntityBody.deserializeAndSetData(entityDataBytes, httpHeaderLine.getHeaderLineMap().get(HttpHeaderLineNameConstant.ENTITY_DATA_CLASS_NAME));
    }

}
